package Input;


import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;

import com.apple.crypto.provider.KeychainStore;

import AI.Crew.Crew;
import AI.Crew.CrewType;
import AI.Crew.Ensign;
import Announcements.Announcement;
import Events.CrewArrival;
import Events.Event;

import Main.SpaceGame;
import Menus.HireMenu;

public class HireMenuInput implements KeyListener 
{
	HireMenu menu;
	SpaceGame main;
	CrewArrival a;
	private ArrayList<Integer> allowedKeys = new ArrayList<Integer>();
	public HireMenuInput(SpaceGame main,HireMenu m) 
	{
		allowedKeys.add(KeyEvent.VK_C);
		this.main = main;
		this.menu = m;
	}

	public void keyPressed(KeyEvent e) 
	{
		if (menu.hireList.size() <= 0 && allowedKeys.contains(e.getKeyCode()))
		{
			a = new CrewArrival();
			a.init(main);
			a.setMenu(menu);
			main.eventHandler.events.add(a);
		}
		
		if (e.getKeyCode() == KeyEvent.VK_C)
		{
			if (main.resources.getBiomass() >= CrewType.Ensign.getCost())
			{
				main.resources.setBiomass(main.resources.getBiomass() - CrewType.Ensign.getCost());
				menu.hireList.add(new Ensign(-1, -1, main, 100));
			}
			else
				main.announcementManager.AddAnnouncement(new Announcement("You dont have enough biomatter!", Color.red));
		}
		
		if (allowedKeys.contains(e.getKeyCode()))
		{
			for(Event c:main.eventHandler.events)
			{
				if (c instanceof CrewArrival)
				{
					((CrewArrival) c).entities = menu.hireList;
				}
			}
		}
	}

	public void keyReleased(KeyEvent arg0) 
	{
		
	}

	public void keyTyped(KeyEvent arg0) 
	{
		
	}
	
}